/*
Copyright (C) 2021-2025 Casa Xu (also Zhiyan Xu) from HIT

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*
 * LOS_FotonAmur.h
 *
 *  Created on: 2023年4月16日
 *      Author: 64435
 */

#ifndef PERIPHERAL_LAYER_INC_LOS_FOTONAMUR_H_
#define PERIPHERAL_LAYER_INC_LOS_FOTONAMUR_H_

#include "LOS_SYS.h"

#define FotonAmur_MAXNUM LOS_MAX14830_NUM1
#define FotonAmur_MAXPort 0

typedef struct LOS_FotonAmur_t
{
    uint8_t VAL;    //数据有效性标志，0：有效， 其他值：无效
    uint8_t CMD;    //开关机指令状态,发送开机指令后置1，发送关机指令后置0
    uint8_t PWR;    //电源状态，读取电源遥测，通电为1，断电为0
    uint8_t MSG;            //通信状态，通信正常为0，通信异常为其他值
    uint8_t HL_TXF;     //HL_前缀表示健康管理相关变量。遥测请求发送完成标志,发送一次后该量置1，接收到回应后置0(TX FINISHED)
    uint8_t HL_WCNT;        //等待接收计数器。该计数器在操作系统的一个线程中累加，当HL_TXF为1时该值+1，HL_TXF为0时该值清0，当累加到一定值时系统会判断通信异常，并将MSG置1
    uint32_t PWRON_Time;   //上电时刻，记录上电指令发出时计算机累计运行时间
    uint32_t PWRDOWN_Time; //下电时刻，记录下电序列指令发出时计算机累计运行时间
    uint8_t flag1;         //用于标识该步操作是否已经执行0：未执行 1：已执行
    uint8_t flag2;
    uint32_t argprd;    //计算机向载荷发送数据包的周期控制     
}LOS_FotonAmur_t;

typedef struct FotonAmurCMD_t
{
    uint16_t length;  //数据长度
    uint8_t msgid[2]; //消息ID，提前按小端形式填好
    uint8_t data[32]; //数据，最长32字节
}FotonAmurCMD_t;

LOS_FotonAmur_t STA_FotonAmur;

FotonAmurCMD_t AmurCMD_TEMP;
FotonAmurCMD_t AmurCMD_Q1;
FotonAmurCMD_t AmurCMD_Q2;
FotonAmurCMD_t AmurCMD_Q3;
FotonAmurCMD_t AmurCMD_Q4;
FotonAmurCMD_t AmurCMD_SHUTDOWN;
FotonAmurCMD_t AmurCMD_Time;
FotonAmurCMD_t AmurCMD_SHUTDOWN;

void LOS_FotonAmur_check();
void LOS_FotonAmur_SendCommand(FotonAmurCMD_t cmd);
void LOS_FotonAmur_SetTime();
void LOS_FotonAmur_ClearBuf();
void LOS_FotonAmur_Shutdown();
void LOS_FotonAmur_ShowTime();
void LOS_FotonAmur_GetTemp();
void LOS_FotonAmur_InitStruct();
void LOS_FotonAmur_PWROn();
void LOS_FotonAmur_PWROff();
void LOS_FotonAmur_TC(uint8_t* data);
uint8_t LOS_FotonAmur_PackCommand(FotonAmurCMD_t cmd, uint8_t* packet);
void LOS_FotonAmur_NewPack();

#define RUN_PROGRAM 1
#define ADC1_MUX1_PGAx1 2
#define ADC1_MUX2_PGAx1 3
#define ADC1_MUX3_PGAx1 4
#define ADC1_MUX4_PGAx1 5
#define STOP_PROGRAM 6
#define ADC1_MUX1_PGAx4 7
#define ADC1_MUX2_PGAx4 8
#define ADC1_MUX3_PGAx4 9
#define ADC1_MUX4_PGAx4 10
#define GET_INFO 11
#define ADC2_MUX1_PGAx1 12
#define ADC2_MUX2_PGAx1 13
#define ADC2_MUX3_PGAx1 14
#define ADC2_MUX4_PGAx1 15
#define READ_FLASH_PAGE_HEADERS 16
#define SCAN_I2C_BUS 17
#define GET_LOGS 18
#define ADC2_MUX1_PGAx4 19
#define ADC2_MUX2_PGAx4 20
#define ADC2_MUX3_PGAx4 21
#define ADC2_MUX4_PGAx4 22
#define TEST_LIGHT_SENSOR 23


#endif /* PERIPHERAL_LAYER_INC_LOS_FOTONAMUR_H_ */
